var isPoint = false;
var isPolyline = false;
var isPolygon_line = false;
var isPolygon_fill = false;
var resourceSource; //原geojson数据源
var drawDataSource; // 绘制数据源
var targetDataSource; //绘制目标图层
var tempDataSource; //临时图层，存放绘制线面过程中的临时数据
var isclear = false;
var isWitget = false;
var line;
var PolygonPointArray_line = null;
var PolygonPointArray_fill = null;
var PolylineArray = null;
var isAttachDraw = false;
//添加线类型判断 
var LineStyle = "";
//添加面类型判断 
var polygonStyle = "";

//标绘点(实际上是标注点)存储
var markerPointArr = [];
var currentWidgetId = "";
var currentWidgetName = "";
var currentEntitie;

var widget = {
    //添加标绘列表 
    addWidgetDoc: function (oId, name) {
        var oDocHtml = "";
        oDocHtml += "<div class=\"docItem\" id=\"" + oId + "\">";
        oDocHtml += "  <div class=\"docTitle\">";
        oDocHtml += "		<i class=\"docClose\"></i>";
        oDocHtml += "		<i class=\"docImg\"></i>";
        oDocHtml += "		<span class=\"docName\">" + name + "</span>";
        oDocHtml += "		<i class=\"right docDel\"></i>";
        oDocHtml += "		<i class=\"right docEdit\"></i>";
        oDocHtml += "		<i class=\"right docSave\"></i>";
        oDocHtml += "		<i class=\"right docAdd\">";
        oDocHtml += "			<ul style=\"height:70px;left:-78px;\">";
        oDocHtml += "				<li data-type=\"point\">添加点标绘</li>";
        oDocHtml += "				<li data-type=\"line\">添加线标绘</li>";
        oDocHtml += "				<li data-type=\"polygon\">添加面标绘</li>";
        oDocHtml += "			</ul>";
        oDocHtml += "		</i>";
        oDocHtml += "	 </div>";
        oDocHtml += "	 <div class=\"docBody\"></div>";
        oDocHtml += "</div>";
        $("#widgetpanel .widgetBox").append(oDocHtml);

        if ($("#widgetpanel .widgetBox").is(":hidden"))
            $("#widgetpanel .widgetBox").show();
    },
    //添加点标绘到列表 
    addWidget: function (oId, otype, Color, name) {
        var oPointHtml = "";
        oPointHtml += "<div class=\"monomerItem " + otype + "\" id=\"" + oId + "\">";
        oPointHtml += "	<i class=\"monomerColor " + otype + "\" style=\"background-color:" + Color + ";\"></i>";
        oPointHtml += "	<span>" + name + "</span>";
        oPointHtml += "	<i class=\"right monomerDel\"></i>";
        oPointHtml += "	<i class=\"right monomerEdit\"></i>";
        oPointHtml += "</div>";
        if (currentWidgetId == sceneid) {
            $("#widgetpanel .widgetBox").prepend(oPointHtml);
        } else {
            $("#" + currentWidgetId + " .docBody").prepend(oPointHtml);
            $("#" + currentWidgetId).find(".docTitle").removeClass("active");
        }
        if ($("#widgetpanel .widgetBox").children().length > 3) {
            $("#widgetpanel .widgetBox").show();
        }
    },
    loadWidget: function () {
        var allDataSource = viewer.dataSources._dataSources;
        var isHaveAttach = false;
        for (var a = 0; a < allDataSource.length; a++) {
            if (allDataSource[a]._sourceUri.indexOf("draw.geojson") != -1) {
                drawDataSource = allDataSource[a];
                var entities = drawDataSource.entities._entities._array;
                for (var i = 0; i < entities.length; i++) {
                    var entity = entities[i];
                    var entityType = entity.properties["polygonType"]._value;
                    var ParentId = entity.properties["parentId"]._value;
                    var ParentName = entity.properties["parentName"]._value;
                    var WidgetId = entity.id;
                    currentWidgetId = ParentId;
                    var ParentHave = $("#" + ParentId).length;
                    var WidgetName = entity.name;
                    if (ParentHave <= 0 && ParentId != sceneid) {
                        widget.addWidgetDoc(ParentId, ParentName);
                    }
                    if (entityType == "point") {
                        var WidgetColor = entity.properties["marker-color"]._value;
                        widget.addWidget(WidgetId, "point", WidgetColor, WidgetName);
                    } else if (entityType == "line") {
                        var WidgetColor = entity.properties["stroke"]._value;
                        widget.addWidget(WidgetId, "line", WidgetColor, WidgetName);
                    } else if (entityType == "polygon") {
                        var WidgetColor = entity.properties["fill"]._value;
                        var WidgetName = entity.name;
                        widget.addWidget(WidgetId, "polygon", WidgetColor, WidgetName);

                        //设置标绘高度
                        if (entity.properties["whfHeight"]) {
                            entity.polygon.extrudedHeight = entity.properties["whfHeight"]._value;
                        }
                    }
                }
                if ($(".widgetBox").children().length <= 3) {
                    $(".widgetBox").hide();
                } else {
                    $(".widgetBox").show();
                }
                isHaveAttach = true;
            }
        }
        if (!isHaveAttach) {
            var sTimeSecondes = new Date().getTime();
            var geojsonUrl = basePath + "/attach/" + sceneid + "/draw.geojson?" + sTimeSecondes;
            var promise = LSGlobe.GeoJsonDataSource.load(geojsonUrl, {
                /* clampToGround : true,
                attachPolygon : true */
            });
            promise.then(function (dataSource) {
                drawDataSource = dataSource;
                viewer.dataSources.add(dataSource);
                var entities = dataSource.entities._entities._array;
                for (var i = 0; i < entities.length; i++) {
                    var entity = entities[i];
                    var entityType = entity.properties["polygonType"]._value;
                    var ParentId = entity.properties["parentId"]._value;
                    var ParentName = entity.properties["parentName"]._value;
                    var WidgetId = entity.id;
                    currentWidgetId = ParentId;
                    var ParentHave = $("#" + ParentId).length;
                    var WidgetName = entity.name;
                    if (ParentHave <= 0 && ParentId != sceneid) {
                        widget.addWidgetDoc(ParentId, ParentName);
                    }
                    if (entityType == "point") {
                        var WidgetColor = entity.properties["marker-color"]._value;
                        widget.addWidget(WidgetId, "point", WidgetColor, WidgetName);
                    } else if (entityType == "line") {
                        var WidgetColor = entity.properties["stroke"]._value;
                        widget.addWidget(WidgetId, "line", WidgetColor, WidgetName);
                    } else if (entityType == "polygon") {
                        var WidgetColor = entity.properties["fill"]._value;
                        var WidgetName = entity.name;
                        widget.addWidget(WidgetId, "polygon", WidgetColor, WidgetName);

                        //设置标绘高度
                        if (entity.properties["whfHeight"]) {
                            entity.polygon.extrudedHeight = entity.properties["whfHeight"]._value;
                        }
                    }
                }
            }).otherwise(function (error) {
                $("#dantihua").parents(".monomer").remove();
            });
            /*  
            var geojsonUrl = basePath + "/attach/"	+ sceneid + "/draw.geojson";
            var promise = LSGlobe.GeoJsonDataSource.load(geojsonUrl,{name:""});promise.then(function(dataSource) {
            drawDataSource = dataSource;
            viewer.dataSources.add(dataSource);}).otherwise(function(error) {
            $("#dantihua").parents(".monomer").remove();
            console.log(error);
            }); 
            */
        }

    },
    //提交标绘 
    uploadWidget: function (bool) {
        if (drawDataSource != undefined) {
            var geojson = drawDataSource.toGeoJson();
            var geoJsonStr = JSON.stringify(geojson);
            var url = basePath + "/" + "uploadGeojson.action";
            $.ajax({
                url: url,
                type: "post",
                data: {
                    guid: sceneid,
                    geojson: geoJsonStr,
                    type: 2
                },
                async: false,
                dataType: "JSON",
                success: function (result) {
                    console.log(result);
                    if (result.resultCode == "1") {
                        if (!bool) {
                            $('body').dailog({
                                type: 'danger',
                                bottons: ['确定'],
                                discription: "提交成功"
                            });
                        }
                    } else {
                        if (!bool) {
                            $('body').dailog({
                                type: 'danger',
                                bottons: ['确定'],
                                discription: "提交失败 "
                            });
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    uploadResult = false;
                }
            });
        }
    },
    widgetChange: function (This) {
        var sThis = This;
        var oLength = $(This).val();
        var oWidth = oLength;
        $(This).next().html(oWidth + "%");
        $(sThis).attr("style", "background-size:" + oWidth + "% 100%;height:4px;border-radius:2px;");
        $(sThis).val(oLength);
        $(sThis).next().val(oLength);
        console.log($(sThis).hasClass(".polygonColorA"))
        if ($(sThis).hasClass("polygonColorA")) {
            var oColor = $("#polygon .polygonColor").val();
            currentEntitie.polygon.material = LSGlobe.Color.fromCssColorString(oColor).withAlpha(oWidth / 100);
        } else if ($(sThis).hasClass("polygonOutcolorA")) {
            var oColor = $("#polygon .polygonOutcolor").val();
            currentEntitie.polygon.outlineColor = LSGlobe.Color.fromCssColorString(oColor).withAlpha(oWidth / 100);
        } else if ($(sThis).hasClass("lineColorA")) {
            var oColor = $("#lineStyle .lineColor").val();
            currentEntitie.polyline.material = LSGlobe.Color.fromCssColorString(oColor).withAlpha(oWidth / 100);

        }
    },
    //geojson 加载点线面 
    drawPoint: function () {
        /* var drawEntity =  $("#drawEntityPropertiesDiv", parent.window.document);
        var plotOper = $(".plotting-oper", parent.window.document);
        drawEntity.addClass("hidden");
        plotOper.after(drawEntity); */
        if (!drawDataSource) {
            var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("drawDataSource"));
            promise.then(function (dataSource) {
                drawDataSource = dataSource;
            }).otherwise(function (error) {

            });
        }
        targetDataSource = drawDataSource;
        isPoint = true;
        isPolyline = false;
        isPolygon_line = false;
        isPolygon_fill = false;
        isStartDraw = false;
        isDraw = true;
        isAttachDraw = false;
        tempDataSource.show = true;
        isFlattenDraw = false;
        isAddMarker = false;
    },
    //绘制面
    drawPolygon: function () {
        if (!drawDataSource) {
            var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("drawDataSource", { /*"clampToGround":true*/ }));
            promise.then(function (dataSource) {
                drawDataSource = dataSource;
            }).otherwise(function (error) {

            });
        }
        targetDataSource = drawDataSource;
        isPoint = false;
        isPolyline = false;
        isPolygon_line = false;
        isPolygon_fill = true;
        isStartDraw = false;
        tempDataSource.show = true;
        isDraw = true;
        isAttachDraw = false;
        isFlattenDraw = false;
        isAddMarker = false;
        isWitget = true;
    },
    //绘制线
    drawLine: function () {
        if (!drawDataSource) {
            var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("drawDataSource"));
            promise.then(function (dataSource) {
                drawDataSource = dataSource;
            }).otherwise(function (error) {

            });
        }
        targetDataSource = drawDataSource;
        isPoint = false;
        isPolyline = true;
        isPolygon_line = false;
        isPolygon_fill = false;
        isStartDraw = false;
        isDraw = true;
        isWitget = true;
        isAttachDraw = false;
        isFlattenDraw = false;
        tempDataSource.show = true;
        isAddMarker = false;
    },
    //飞到标绘位置 
    flytoEntity: function (id, type) {
        var entity = undefined;
        entity = drawDataSource.entities.getById(id);
        if (!entity) {
            return;
        }
        viewer.flyTo(entity);
    },

    init: function () {
        //模型标绘点开显示下拉框【两级】
        $(document).on("click", "#widgetpanel .addmonomer,#widgetpanel .docAdd", function () {
            var oThis = $(this);
            oThis.addClass(".active");
            oThis.find("ul").show();
        });
        //模型标绘收起下拉框【两级】
        $(document).on("mouseleave", "#widgetpanel .addmonomer ul,#widgetpanel .docAdd ul", function () {
            $(this).hide();
        });


        //添加文件夹，点，线，面
        $(document).on("click", "#widgetpanel .rootTitle li,#widgetpanel .docTitle li", function () {
            var oThis = $(this);
            //var randomguid = new GUID();
            var widgetId = baseSetting.newRandomGuid();
            if (oThis.parent().parent().hasClass("addmonomer")) {
                currentWidgetId = sceneid;
                currentWidgetName = "";
            } else {
                currentWidgetId = oThis.parents(".docItem").eq(0).attr("id");
                currentWidgetName = oThis.parents(".docTitle").find(".docName").html();
            }
            var oType = oThis.attr("data-type");
            if (oType == "doc") {
                widget.addWidgetDoc(widgetId, "新分类");
            } else if (oType == "point") {
                widget.drawPoint();
            } else if (oType == "line") {
                widget.drawLine();
            } else if (oType == "polygon") {
                widget.drawPolygon();
            }
            oThis.parent().hide();
        });

        /*文件夹的删除 */
        $(document).on("click", "#widgetpanel .docDel", function () {
            var _parent = $(this).parent().parent();
            var parentId = _parent.attr("id");

            $(_parent.find(".monomerItem")).each(function () {
                var objId = $(this).attr("id");
                drawDataSource.entities.removeById(objId);
            });
            _parent.remove();
            if ($(".widgetBox").find(".docItem").length == 0)
                $("#widgetpanel .widgetBox").hide();
        });

        //删除标绘 
        $(document).on("click", "#widgetpanel .monomerDel", function () {
            var oId = $(this).parents(".monomerItem ").attr("id");
            drawDataSource.entities.removeById(oId);
            $(this).parents(".monomerItem").remove();
            if ($("#widgetpanel .widgetBox").children().length <= 3) {
                $("#widgetpanel .widgetBox").hide();
            }
        });


        /* 文件夹关闭打开 */
        $(document).on("click", "#widgetpanel .docClose,#widgetpanel .monomerClose,#pushpanel .monomerClose", function () {
            var oParent = $(this).parent();
            if (oParent.hasClass("active")) {
                oParent.removeClass("active")
            } else {
                oParent.addClass("active")
            }
        });

        /* 点击飞到 标绘的位置 */
        $(document).on("click", "#widgetpanel .monomerItem", function () {
            var oId = $(this).attr("id");
            widget.flytoEntity(oId, 1);
        });
        /*文件夹编辑*/
        $(document).on("click", "#widgetpanel .docEdit", function () {
            var oThis = $(this);
            var oText = oThis.siblings(".docName").html();
            oThis.hide().siblings(".docSave").show();
            oThis.siblings(".docName").html("<input type=\"text\" value=\"" + oText + "\">");
        });
        /*文件夹名称修改 */
        $(document).on("blur", "#widgetpanel .docName input", function () {
            var oThis = $(this);
            var oText = oThis.val();
            var oId = oThis.parents(".docItem").eq(0).attr("id");
            if ($.trim(oText) == "") {
                $('body').dailog({
                    type: 'danger',
                    bottons: ['确定'],
                    discription: "分类名不能为空"
                });
            } else {
                oThis.parent().siblings(".docEdit").show().siblings(".docSave").hide();
                oThis.parent().html(oText);
                var oChildren = $('#' + oId).find(".docBody .monomerItem");
                for (var a = 0; a < oChildren.length; a++) {
                    var oChildId = oChildren.eq(a).attr("id");
                    drawDataSource.entities.getById(oChildId).properties["parentName"] = oText;
                }
            }
        });
        $(document).on("keydown", "#widgetpanel .docName input", function (e) {
            if (e.keyCode == 13) {
                var oThis = $(this);
                var oText = oThis.val();
                var oId = oThis.parents(".docItem").eq(0).attr("id");
                if ($.trim(oText) == "") {
                    $('body').dailog({
                        type: 'danger',
                        bottons: ['确定'],
                        discription: "分类名不能为空"
                    });
                } else {
                    oThis.parent().siblings(".docEdit").show().siblings(".docSave").hide();
                    oThis.parent().html(oText);
                    var oChildren = $('#' + oId).find(".docBody .monomerItem");
                    for (var a = 0; a < oChildren.length; a++) {
                        var oChildId = oChildren.eq(a).attr("id");
                        drawDataSource.entities.getById(oChildId).properties["parentName"] = oText;
                    }
                }
            }
        });
        $(document).on("click", "#widgetpanel .docSave", function () {
            var oThis = $(this);
            var oText = oThis.siblings(".docName").find("input").val();
            var oId = oThis.parents(".docItem").eq(0).attr("id");
            if ($.trim(oText) == "") {
                $('body').dailog({
                    type: 'danger',
                    bottons: ['确定'],
                    discription: "分类名不能为空"
                });
            } else {
                oThis.hide().siblings(".docEdit").show();
                oThis.siblings(".docName").html(oText);
                var oChildren = $('#' + oId).find(".docBody .monomerItem");
                for (var a = 0; a < oChildren.length; a++) {
                    var oChildId = oChildren.eq(a).attr("id");
                    drawDataSource.entities.getById(oChildId).properties["parentName"] = oText;
                }
            }
        });



        //标绘是否填充
        $(document).on("click", "#polygon .polygonfill", function () {
            console.log("aaa");
            var oThis = $(this);
            if (oThis.hasClass("active")) {
                oThis.removeClass("active");
                currentEntitie.polygon.fill = false;
            } else {
                oThis.addClass("active");
                currentEntitie.polygon.fill = true;
            }
        });
        //是否显示边框 
        $(document).on("click", "#polygon .polygonOutline", function () {
            var oThis = $(this);
            if (oThis.hasClass("active")) {
                oThis.removeClass("active");
                currentEntitie.polygon.outline = false;
            } else {
                oThis.addClass("active");
                currentEntitie.polygon.outline = true;
            }
        });
        //柱状高度设置
        $(document).on("blur", ".txtEntityHeight", function () {
            var hX = parseInt($(this).val());
            var existPropertyX = false;
            var pros = currentEntitie.properties._propertyNames;
            for (var k = 0; k < pros.length; k++) {
                if (pros[k] == "whfHeight") {
                    existPropertyX = true;
                    break;
                }
            }

            if (existPropertyX) {
                currentEntitie.properties.whfHeight = hX;
            } else
                currentEntitie.properties.addProperty("whfHeight", hX)

            //赋值圆柱体
            currentEntitie.polygon.extrudedHeight = hX;
        });

        //polygonColor
        $(document).on("change", "#polygon .polygonColor", function () {
            var oThis = $(this).val();
            var polygon = $("#polygon .polygonColorA").val();
            currentEntitie.polygon.material = LSGlobe.Color.fromCssColorString(oThis).withAlpha(polygon / 100);
            var htmlid = currentEntitie.id;
            $("#" + htmlid).find(".monomerColor.polygon").css({
                "background-color": oThis
            });
        });
        //polygonOutcolor
        $(document).on("change", "#polygon .polygonOutcolor", function () {
            var oThis = $(this).val();
            currentEntitie.polygon.outlineColor = LSGlobe.Color.fromCssColorString(oThis)
        });
        //线的宽度设置 
        $(document).on("click", "#polygon .menuUp", function () {
            var oThis = $(this);
            $("#polygon").find("ul").hide()
            oThis.parents("label").next().show();
        });
        $(document).on("click", "#polygon .width  ul li", function () {
            var oThis = $(this);
            var Linewidth = oThis.attr("data-type");
            currentEntitie.polygon.outlineWidth = Linewidth;
            oThis.parents("ul").hide();
        });
        $(document).on("click", "#polygon .style  ul li", function () {
            var oThis = $(this);
            var Linewidth = oThis.attr("data-type");
            if (Linewidth == "solid") {
                currentEntitie.polygon.outlineWidth = Linewidth;
            } else if (Linewidth == "dot") {
                currentEntitie.polygon.outlineWidth = Linewidth;
            }
            oThis.parents("ul").hide();
        });
        //线属性编辑 
        $(document).on("click", "#lineStyle .menuUp", function () {
            var oThis = $(this);
            $("#lineStyle").find("ul").hide()
            oThis.parents("label").next().show();
        });
        $(document).on("click", "#lineStyle .width  ul li", function () {
            var oThis = $(this);
            var Linewidth = oThis.attr("data-type");
            currentEntitie.polyline.width = Linewidth;
            oThis.parents("ul").prev().find("font").css({
                "background-position": "10px -" + 20 * ((Linewidth / 2) - 1) + "px"
            });
            oThis.parents("ul").hide();
        });

        $(document).on("change", "#lineStyle .lineColor", function () {
            var oThis = $(this).val();
            var lineA = $("#lineStyle .lineColorA").val()
            currentEntitie.polyline.material = LSGlobe.Color.fromCssColorString(oThis).withAlpha(lineA / 100);
            var htmlid = currentEntitie.id;
            $("#" + htmlid).find(".monomerColor.line").css({
                "background-color": oThis
            });
        });
        $(document).on("click", "#lineStyle .style  ul li", function () {
            var oThis = $(this);
            var LineStyle = oThis.attr("data-type");
            var lineColor = $("#lineStyle .lineColorA").val();
            var lineA = $("#lineStyle .lineColorA").val();
            if (LineStyle == "solid") {
                oThis.parents("ul").prev().find("font").css({
                    "background-position": "0 0"
                });
                currentEntitie.polyline.material = LSGlobe.Color.fromCssColorString(lineColor)
            } else if (LineStyle == "dot") {
                oThis.parents("ul").prev().find("font").css({
                    "background-position": "0 -20px"
                });
                currentEntitie.polyline.material = new LSGlobe.PolylineDashMaterialProperty({
                    color: LSGlobe.Color.fromCssColorString(lineColor)
                })
            }
            oThis.parents("ul").hide();
        });


        /*单个标绘编辑*/
        $(document).on("click", "#widgetpanel .monomerEdit", function () {
            console.log("ssss");
            var oThis = $(this);
            var oParent = oThis.parents(".monomerItem");
            var oId = oParent.attr("id");
            var entitie = drawDataSource.entities.getById(oId);
            currentEntitie = entitie;
            if (oParent.hasClass("point")) {
                var WidgetName = entitie.name;
                var WidgetSize = entitie.point.pixelSize._value;
                var WidgetColor = entitie.point.color;
                var PointHtml = $("#pointStyle");
                PointHtml.find(".entityName").val(WidgetName);
                PointHtml.find(".pointSize").val(WidgetSize);
                PointHtml.find(".pointColor").val(WidgetColor.toString().colorHex());
                $("#pointStyle").show();
                $("#lineStyle,#polygon").hide();
                oParent.after(PointHtml);
            } else if (oParent.hasClass("line")) {
                var PointHtml = $("#lineStyle");
                var WidgetName = entitie.name;
                var WidgetColor = entitie.polyline.material._color;
                var WidgetA = entitie.polyline.material._color._value.alpha;
                var WidgetWidth = entitie.polyline.width;
                PointHtml.find(".entityName").val(WidgetName);
                PointHtml.find(".lineColor").val(WidgetColor.toString().colorHex());
                PointHtml.find(".lineColorA").val(Math.ceil(WidgetA * 100));
                PointHtml.find(".lineColorA").css({
                    "background-size": "" + Math.ceil(WidgetA * 100) + "% 100%"
                });
                PointHtml.find(".lineColorA").next().html(Math.ceil(WidgetA * 100) + "%");
                PointHtml.find(".polygonW").css({
                    "background-position": "10px -" + 20 * ((WidgetWidth / 2) - 1) + "px"
                });
                $("#lineStyle").show();
                $("#pointStyle,#polygon").hide();
                oParent.after(PointHtml);
            } else if (oParent.hasClass("polygon")) {
                var WidgetName = entitie.name;
                var WidgetFillColor = entitie.polygon.material._color;
                var WidgetFillColorA = entitie.polygon.material._color._value.alpha;
                var WidgetOutline = entitie.polygon.outline._value;
                var WidgetOutcolor = entitie.polygon.outlineColor;
                var WidgetOutcolorA = entitie.polygon.outlineColor._value.alpha;
                var PointHtml = $("#polygon");
                PointHtml.find(".entityName").val(WidgetName);

                console.log(WidgetFillColorA);
                if (WidgetFillColorA != "0") {
                    PointHtml.find(".polygonfill").addClass("active");
                } else {
                    PointHtml.find(".polygonfill").removeClass("active");
                }
                PointHtml.find(".polygonColor").val(WidgetFillColor.toString().colorHex());
                PointHtml.find(".polygonColorA").val(Math.ceil(WidgetFillColorA * 100));
                PointHtml.find(".polygonColorA").css({
                    "background-size": "" + Math.ceil(WidgetFillColorA * 100) + "% 100%"
                });
                PointHtml.find(".polygonColorA").next().html(Math.ceil(WidgetFillColorA * 100) + "%");
                if (WidgetOutcolorA != "0") {
                    PointHtml.find(".polygonOutline").addClass("active");
                } else {
                    PointHtml.find(".polygonOutline").removeClass("active");
                }
                PointHtml.find(".polygonOutcolor").val(WidgetOutcolor.toString().colorHex());
                PointHtml.find(".polygonOutcolorA").val(Math.ceil(WidgetOutcolorA * 100));
                PointHtml.find(".polygonOutcolorA").css({
                    "background-size": "" + Math.ceil(WidgetOutcolorA * 100) + "% 100%"
                });
                PointHtml.find(".polygonOutcolorA").next().html(Math.ceil(WidgetOutcolorA * 100) + "%");

                PointHtml.find(".txtEntityHeight").val(entitie._properties.whfHeight._value);
                $("#polygon").show();
                $("#pointStyle,#lineStyle").hide();
                oParent.after(PointHtml);
            }
            return false;
        });
        //点标绘编辑 
        //编辑名称
        $(document).on("blur", "#pointStyle .entityName,#polygon .entityName,#lineStyle .entityName", function () {
            var oText = $(this).val();
            currentEntitie.name = oText;
            var htmlid = currentEntitie.id;
            if ($.trim(oText) == "") {
                $('body').dailog({
                    type: 'danger',
                    bottons: ['确定'],
                    discription: "名称不能为空"
                });
                $(this).val("未命名");
                $("#" + htmlid).find("span").html("未命名");
            } else {
                $(this).val(oText);
                $("#" + htmlid).find("span").html(oText);
            }
        });
        //编辑大小 
        $(document).on("change blur", "#pointStyle .pointSize", function () {
            var oText = $(this).val();
            var validLat = /^(-)?[0-9]+([.]{1}[0-9]+){0,1}$/;
            if (validLat.test(oText) && oText >= 10 && oText <= 30) {
                currentEntitie.point.pixelSize = oText;
            } else {
                $('body').dailog({
                    type: 'danger',
                    bottons: ['确定'],
                    discription: "请输入8~30的数字"
                });
                $(this).val("10");
                var htmlid = currentEntitie.point.pixelSize = "10";
                return;
            }

        });
        //编辑大小 
        $(document).on("change", "#pointStyle .pointColor", function () {
            var oText = $(this).val();
            currentEntitie.point.color = LSGlobe.Color.fromCssColorString(oText);
            var htmlid = currentEntitie.id;
            $("#" + htmlid).find(".monomerColor.point").css({
                "background-color": oText
            });
        });
        $(document).on("click", "#pointStyle .pointSure,#lineStyle .lineSure,#polygon .polygonSure", function () {
            $(this).parents(".monomerEditPop ").hide();
            widget.uploadWidget("edit");
        });
    }
}